<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-xs-12">
		<div class="btn-group m-b-1" role="group">
			<?php echo admin_tab_active($menu['pay']['tab'], 'gateway');?>
		</div>
	</div>
</div>

<div class="row">
	<div class="col-lg-12">
		<div class="card">
			<div class="table-responsive">
				<form action="<?php echo url('pay-gateway');?>" method="POST">
					<table class="table" style="min-width: 800px">
						<thead>
							<tr>
								<th class="text-center" width="60">删除</th>
								<th class="text-center" width="80">简称</th>
								<th class="text-center" width="50">名称</th>
								<th class="text-center" width="60">APPID</th>
								<th class="text-center" width="250">密匙</th>
								<th class="text-center">公匙</th>
                              	<th class="text-center" width="300">地址</th>
								<th class="text-center" width="60">状态</th>
							</tr>
						</thead>
						<tbody id="userlist">
							<?php if($gateway){foreach($gateway as $l){ ?>
							<tr uid="<?php echo $l['id']; ?>">
								<td class="text-center"><input type="checkbox" name="delete" /></td>
								<td class="text-center"><?php echo $l['shortname'];?></td>
								<td class="text-center"><input class="form-control" name="name[<?php echo $l['id'];?>]" value="<?php echo $l['name'];?>"></td>
								<td class="text-center"><input class="form-control" name="id[<?php echo $l['id'];?>]" value="<?php echo $l['api_id'];?>"></td>
								<td class="text-center"><input class="form-control" name="secret[<?php echo $l['id'];?>]" value="<?php echo $l['api_secret'];?>"></td>
								<td class="text-center"><input class="form-control" name="publickey[<?php echo $l['id'];?>]" value="<?php echo $l['api_publickey'];?>"></td>
                              	<td class="text-center"><input class="form-control" name="url[<?php echo $l['id'];?>]" value="<?php echo $l['url'];?>"></td>
								<td class="text-center"><?php echo $l['status']==1?'<b style="color:#FF0000;">异常</b>':'正常'; ?></td>
							</tr>
							<?php }} ?>
						</tbody>
					</table>
					<div class="row" style="margin:5px 10px;">
						<div class="col-lg-2">
							<div class="form-group">
								<a class="btn btn-primary active" href="pay-gatewayadd.htm">添加网关</a>
							</div>
						</div>
						<div class="col-lg-2">
							<div class="form-group">
								<input type="password" class="form-control" id="passcode" name="passcode" value="" placeholder="输入安全码">
							</div>
						</div>
						<div class="col-lg-2">
							<div class="form-group">
								<input type="button" class="btn btn-warning" id="confirm" value="删除">
								<input type="button" class="btn btn-primary" id="submit" value="提交修改">
							</div>
						</div>
					</div>
				</form>
			</div>
			<hr class="m-t-0" />
		</div>
		<nav class="text-center"><ul class="pagination"><?php echo $pagination; ?></ul></nav>
	</div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<script>

var jform = $('form');
$('#submit').click(function(){
	var postdata = jform.serialize();
	$.xpost(jform.attr('action'), postdata, function(code, message){
		$.alert(message);
		if(code==1) setTimeout(function(){window.location.reload()}, 1500);
	});
	return false;
});

var jconfirm = $("#confirm");
var juserlist = $('#userlist');
// 删除选中的记录
jconfirm.on('click', function(){
	var jchecked = juserlist.find('input[name="delete"]').filter(function(){ return this.checked; });
	if(jchecked.length < 1) return alert("请选择要删除的网关");
	if(!window.confirm("确认删除？")) return false;
	jchecked.each(function() {
		jtr = $(this).parents('tr');
		var uid = jtr.attr('uid');
		var passcode = $('#passcode').val();
		$.xpost(xn.url('pay-gatewaydel'), {id:uid,passcode:passcode}, function(code, message) {
			$.alert(message);
			if(code != 0) jtr.remove();
		});
	});
});

$('#nav_pc li.pay, #nav_mobile li.pay').tab('show');
</script>